
package com.yuan.servlet;

import com.yuan.hibernate.Users;
import com.yuan.hibernate.UsersDAO;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class changepwdservlet extends BaseHttpServlet {
    private UsersDAO mUsersDAO = null;

    @SuppressWarnings("unchecked")
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        super.doGet(request, response);
        mUsersDAO = new UsersDAO();
        String username = request.getParameter("username");
        String pwd = request.getParameter("pwd");
        String newpwd = request.getParameter("newpwd");
        List<Users> list = mUsersDAO.findByUsername(username);
        if (list.size() == 1 && list.get(0).getPwd().equals(pwd))
        {
            list.get(0).setPwd(newpwd);
            mResponse = "修改成功";
            mUsersDAO.update(list.get(0));
        } else
        {
            mResponse = "修改失败";
        }
        closeAndClear();
    }

    @Override
    protected synchronized void closeAndClear() {
        mUsersDAO = null;
        super.closeAndClear();
    }
}
